package com.chujian.framework.idgen;

import com.baidu.fsg.uid.impl.CachedUidGenerator;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

/**
 * myBatis Id生成器
 * TODO 此类应该有问题，别问我为什么
 */
@Component
@Slf4j
public class UidKeyGenerator implements IKeyGenerator {

    @Autowired
    @Lazy
    private CachedUidGenerator cachedUidGenerator;

    @Override
    public String executeSql(String incrementerName) {
        return "" + cachedUidGenerator.getUID();
    }

    @Override
    public DbType dbType() {
        return DbType.MYSQL;
    }

}
